﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CocisDAL;
using CocisModel;
using CocisModel.Common;
using System.Data;
using CocisWeb.src;

namespace CocisWeb.ManageAsset
{
    public partial class AddIPAssign : System.Web.UI.Page
    {
        public AssetDAL dal = new AssetDAL();
        public LogsDAL logs = new LogsDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.BindDropDownList();
            }
        }

        public void BindDropDownList()
        {
            this.ddlIPRange.DataSource = dal.GetIPRange();
            this.ddlIPRange.DataTextField = "IPRange";
            this.ddlIPRange.DataValueField = "IPRangeID";
            this.ddlIPRange.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Asset.IPAssignDataTable dt = new Asset.IPAssignDataTable();
            Asset.IPAssignRow rows = dt.NewIPAssignRow();
            Guid gd = new Guid();
            rows.IPAssignID = gd;
            rows.IPRangeID = this.ddlIPRange.SelectedValue.ToString();
            rows.IPAddress = this.txtIPAddress.Text;
            rows.Netmask = this.txtNetmask.Text;
            rows.Gateway = this.txtGateway.Text;
            rows.VlanID = this.txtVlanID.Text;
            rows.Usage = this.txtUsage.Text;
            rows.DeviceName = this.txtDeviceName.Text;
            rows.CRQ = this.txtCRQ.Text;

            dt.Rows.Add(rows);
            dt.AcceptChanges();

            int temp = dal.AddIPAssign(dt);
            if (temp > 0)
            {
                string ip = Request.UserHostAddress.ToString();
                ClientScript.RegisterStartupScript(this.GetType(), "a", "<script language=javascript>alert('添加成功！')</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "b", "<script language=javascript>alert('添加失败！')</script>");

            }
        }

    }
}